<script>
  import $ from '../dfish.js'

  export default {
    props: ['pub', 'current'],
    provide() {
      return {
        providePubParent: this
      }
    },
    methods: {
      inCurrent(target) {
        let c = this.x.current
        if (c == null) return
        if (Array.isArray(c)) {
          return -1 < c.findIndex(v => this.isCurrentChild(v, target))
        } else {
          return this.isCurrentChild(c, target)
        }
      },
      isCurrentChild(current, target) {
        if (typeof current === 'object') {
          let d = target.isWidget ? (target.x || target).data : (target.props && target.props.data)
          if (d) {
            for (let i in current)
              if ($.lodash.get(d, i) == current[i]) return true
          }
        } else if (current == (target.isWidget ? target.getKey() : target.key)) {
          return true
        }
      }
    }
  }
</script>
